<?php
namespace My\Model;

use Utuo\UtuoModel;

/**
 * 网站配置模型
 */
class DriverTermModel extends UtuoModel {
	
	// 自动验证
	protected $_validate = array();
	
	// 自动完成
	protected $_auto = array(
		array('config', 'getConfig', self::MODEL_BOTH, 'callback'),
	);
	
	public function getConfig() {
		$config = I('config');
		if( !isset($_REQUEST['config']) or !is_array($_REQUEST['config'])) return false;
		$config['begin_time'] = strtotime($config['begin_time']);
		$config['end_time'] = strtotime($config['end_time']);
		$config['rank_snap_name'] = $config['rank_name']."_SNAP";
		return serialize($config);
	}
	
	public function checkConfig() {
		$config = I('config');
		if ( !$config['begin_time'] or !$config['end_time'] ) {
			$this->error['config'] = '请正确设置开始与结束时间';
			return false;
		}
		if ( !$config['rank_name'] ) {
			$this->error['config'] = '实时排行榜英文标识不能为空';
			return false;
		}
		return true;
	}
	
	// 增加配置信息验证
	public function setupConfigValid() {
		array_push($this->_validate, array('config', 'checkConfig','配置信息不正确', 0, 'callback') );
	}
	
}